﻿Public Class Account_Detail

    Public Shared Sub Update冲账_加(ByVal ct As Db.Vb.CTable, _
                              ByVal dtValue As String, _
                              ByVal userId As String, _
                              ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 冲帐 = 冲帐 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,冲帐) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update冲账_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 冲帐 = 冲帐 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update借入_加(ByVal ct As Db.Vb.CTable, _
                                 ByVal dtValue As String, _
                                 ByVal userId As String, _
                                 ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 借入 = 借入 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,借入) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update借入_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 借入 = 借入 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update还出_加(ByVal ct As Db.Vb.CTable, _
                                 ByVal dtValue As String, _
                                 ByVal userId As String, _
                                 ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 还出 = 还出 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,还出) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update还出_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 还出 = 还出 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())

            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update借出_加(ByVal ct As Db.Vb.CTable, _
                                 ByVal dtValue As String, _
                                 ByVal userId As String, _
                                 ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 借出 = 借出 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,借出) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update借出_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 借出 = 借出 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update还入_加(ByVal ct As Db.Vb.CTable, _
                                 ByVal dtValue As String, _
                                 ByVal userId As String, _
                                 ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 还入 = 还入 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,还入) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update还入_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 还入 = 还入 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update转出_加(ByVal ct As Db.Vb.CTable, _
                                 ByVal dtValue As String, _
                                 ByVal userId As String, _
                                 ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 转出 = 转出 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,转出) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update转出_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 转出 = 转出 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update转入_加(ByVal ct As Db.Vb.CTable, _
                                 ByVal dtValue As String, _
                                 ByVal userId As String, _
                                 ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 转入 = 转入 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,转入) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update转入_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 转入 = 转入 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update收入_加(ByVal ct As Db.Vb.CTable, _
                                 ByVal dtValue As String, _
                                 ByVal userId As String, _
                                 ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 收入 = 收入 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,收入) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update收入_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 收入 = 收入 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update支出_加(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 支出 = 支出 +" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            Dim sbInsert As New StringBuilder
            sbInsert.AppendLine(" Insert into Account_Detail(日期,用户帐户ID,支出) Values(")
            sbInsert.AppendLine("'" & dtValue & "','" & userId & "','" & count & "'")
            sbInsert.AppendLine(")")

            If Not Get日期是否存在(ct, dtValue, userId) Then
                ct.ExecuteSql(sbInsert.ToString())
            Else
                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Sub Update支出_减(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String, _
                                  ByVal count As Decimal)
        Try

            If count = 0 Then
                Return
            End If

            If userId.Trim = "" Then
                Return
            End If

            Dim sbUpdte As New StringBuilder
            sbUpdte.AppendLine(" Update Account_Detail ")
            sbUpdte.AppendLine(" Set 支出 = 支出 -" & count)
            sbUpdte.AppendLine(" Where ")
            sbUpdte.AppendLine("     用户帐户ID='" & userId & "'")
            sbUpdte.AppendLine(" And 日期='" & dtValue & "'")

            If Get日期是否存在(ct, dtValue, userId) Then

                ct.ExecuteSql(sbUpdte.ToString())
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Shared Function Get日期是否存在(ByVal ct As Db.Vb.CTable, _
                                  ByVal dtValue As String, _
                                  ByVal userId As String) As Boolean
        Try
            Dim sb As New StringBuilder
            Dim bExist As Boolean = False
            sb.AppendLine(" select * from Account_Detail where 用户帐户ID='" + userId + "' And 日期 = '" + dtValue + "'")
            Dim rs As ADODB.Recordset = ct.ExecuteSql(sb.ToString())
            If rs.EOF Then
                bExist = False
            Else
                bExist = True
            End If
            rs.Close()
            rs = Nothing
            Return bExist
        Catch ex As Exception
            Return False
        End Try

    End Function
End Class
